import React, { FC, useRef } from 'react';
import TabBar from '../../../components/tab-bar';
import Registration from '../../../components/registration'
import { httpJson } from "../../../services/http";
import { useHistory } from 'react-router-dom';

// 用户注册页
const UserRegistration: FC = props => {
    const infoRef = useRef<any>();
    const history = useHistory();

    const registration = () => {
        console.log("可以获取到用户注册信息：", infoRef.current.getFieldValue())
        delete infoRef.current.getFieldValue().confirmPassword;
        httpJson('POST', '/api/user/register', infoRef.current.getFieldValue())
            .then((res: any) => {
                console.log("用户注册成功返回信息", res);
                if (res.data.code == '200') {
                    history.push({
                        pathname: "/merLogReg/logSuccess",
                        state: { type: "user" }
                    });
                }
            })
            .catch(err => {
                console.log(err)
            })

    }
    return (
        <div>
            <TabBar goBack={() => { console.log("用户返回") }} regText="用户注册" cenText="用户中心" />
            <Registration registration={registration} btnText="注册" ref={infoRef} />
        </div>
    )

}
export default UserRegistration;
